package edu.ynmd.parm.action;

import edu.ynmd.parm.model.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
@ResponseBody
public class PublicAction {
    @RequestMapping("getAnString")
    public String getAnString(){
        return "服务器端返回的字符窜";
    }

    //http://localhost/getParmValue?sid=abc123
    @GetMapping("getParmValue")
    @ResponseBody
    public String getParmValue(@RequestParam String sid){
        return sid;
    }

    //http://localhost/getPathValue/def456
    @GetMapping("getPathValue/{sid}")
    @ResponseBody
    public String getPathValue(@PathVariable(name="sid") String sid){

        return  sid;

    }

//提交的参数
//
//    {
//        "id":"id001",
//            "stunum":"stunum001",
//            "name":"测试姓名"
//
//
//    }

    @PostMapping("receiveAnObject")
    @ResponseBody
    public Student receiveAnObject(@RequestBody Student student){

        return student;
    }

    //form 表单 submit的参数接收
    @PostMapping("receiveAnFormObject")
    @ResponseBody
    public Student receiveAnFormObject(Student student){
        return student;
    }


    @GetMapping("returnList")
    @ResponseBody
    public List<Student> returnList(){
        //泛型
        List<Student> sl= new ArrayList<>();//容器类的实例化
        for(int i=0;i<10;i++){
            Student s=new Student();
            s.setId("id"+i);
            s.setStunum("stunum"+i);
            s.setName("name"+i);
            sl.add(s);//放入的容器对象中
        }
        return sl;

    }
    @PostMapping("receiveAnListParm")
    @ResponseBody
    public List<Student> recieveANListParm(@RequestBody List<Student> sl){

        return sl;

}
}